package com.sync.syncmasterdata.customer.repository.oarep;

import com.sync.syncmasterdata.customer.entity.oa.OACustomerEntity;
import com.sync.syncmasterdata.customer.entity.oa.OACustomerWFEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 客户档案 dao 持久类
 */
@Repository
public interface OACustomerRepository extends JpaRepository<OACustomerEntity,Integer> {

    /**
     * 获取客户OAID
     * @param kehumc
     * @return
     */
    @Query(nativeQuery = true, value= "select id from formtable_main_6 where kehumc=:kehumc and rownum=1")
    String getCustomerID(@Param(value = "kehumc") String kehumc);

    /**
     * 获取客户OAID 名称+id，如果存在多个，报错
     * @param kehumc
     * @param crmid
     * @return
     */
    @Query(nativeQuery = true, value= "select id from formtable_main_6 where kehumc=:kehumc or crmid=:crmid")
    List<String> getCustomerIDByNameAndGuid(@Param(value = "kehumc") String kehumc, @Param(value="crmid") String crmid);

    /**
     * 在数据库 获取OA客户对象 by requestid
     */
    @Query(nativeQuery = true, value= "select * from formtable_main_6 where xiangguansplc=:requestid")
    OACustomerEntity getOACustomerEntityByRequestid(@Param(value = "requestid") String requestid);

    /**
     * 获取oa台账中，存贮的U8客户编码
     * @param kehumc
     * @return map
     */
    @Query(nativeQuery = true, value= "select * from formtable_main_6 where kehumc=:kehumc and rownum=1")
    OACustomerEntity getOACustomerU8ID(@Param(value = "kehumc") String kehumc);

}
